export default {
    data() {
        return {
            radio_id:0,
            type:0,
            operator_id:'',
            operatorList:[],
            name:'',
            page: 1,
            limit: 10,
            count: 0,
            // 表格数据
            tableData: [],
            check_ids:[],           //选择的id
        }
    },
    /**
     * 进入页面加载
     */
    mounted: function () {
        var that = this;
        //在缓存中获取值
        that.user_name = sessionStorage.getItem("user_name");
        that.user_id = sessionStorage.getItem("user_id");
        that.token = sessionStorage.getItem("access-token");
        if ((!that.token) || (!that.user_id) || (!that.user_name)) {
            that.$router.push('/login');
        }

        if (that.$route.query.radio_id) {
            that.radio_id = that.$route.query.radio_id;
            that.getList();
        }
        that.getOperatorList();
    },

    /**
     * 方法
     */
    methods: {

        /**
         * 筛选
         */
        search:function () {
            const that = this;
            that.getList();
        },

        /**
         * 除去邮轮趣玩的列表
         */
        getList() {
            const that = this;
            that.tableData = [];
            //请求的数据
            const formData = {};
            formData.token = that.token;
            formData.type = that.type;
            formData.radio_station_id = that.radio_id;

            if(that.name !== ''){
                formData.keys = that.name;
            }
            if(that.operator_id !== ''){
                formData.seller_id = that.operator_id;
            }
            //请求邀请者列表
            that.$http.post(that.adminApi.api_url + "/Radiostation/addradio_relation_goods", formData, {
                emulateJSON: true
            }).then(
                function (res) {
                    // 处理成功的结果
                    if (res.body) {
                        for (var i in res.body.list) {
                            that.tableData.push({
                                i: i,
                                id: res.body.list[i].goods_id,
                                title: res.body.list[i].title,
                                sn: res.body.list[i].sn,
                                picture: res.body.list[i].picture[0],
                                cost_price: res.body.list[i].cost_price,
                                submit_time: res.body.list[i].submit_time,
                                seller_name: res.body.list[i].seller_name,
                            });
                        }
                        that.count = res.body.count;
                    }
                },
                function () {
                    // 处理失败的结果
                    that.$message({
                        type: 'error',
                        message: `操作提示: ${ '处理异常' }`
                    });
                });
        },


        /**
         * 供应商列表
         */
        getOperatorList:function () {
            const that =this;
            const formData = {};
            formData.token = that.token;
            //请求邀请者列表
            that.$http.post(that.adminApi.api_url + "/Operator/availablelist", formData, {
                emulateJSON: true
            }).then(
                function (res) {
                    // 处理成功的结果
                    if (res.body) {
                        for (var i in res.body) {
                            that.operatorList.push({
                                id: res.body[i].id,
                                name: res.body[i].company,
                            });
                        }
                    }
                },
                function () {
                    // 处理失败的结果
                    that.$message({
                        type: 'error',
                        message: `操作提示: ${ '处理异常' }`
                    });
                });
        },

        /**
         * 返回上一页
         */
        back:function () {
            this.$router.go(-1);
        },

        /**
         * 下一页
         * @param currentPage
         */
        handleCurrentChange: function (currentPage) {
            var that = this;
            that.page = currentPage;
        },


        /**
         * 选择
         * @param e
         */
        handleSelectionChange:function (e) {
            const that = this;
            that.check_ids = [];
            for(var i in e) {
                that.check_ids.push(e[i].id);
            }
        },

        /**
         * 关联期数
         * @returns {boolean}
         */
        bindStage:function () {
            var that= this;
            if(that.check_ids.length === 0){
                that.$message({
                    type: 'error',
                    message: `操作提示: ${ '请选择您关联的产品' }`
                });
                return false;
            }

            //请求的数据
            var formData = {};
            formData.token = that.token;
            formData.radio_station_id = that.radio_id;
            formData.goods_id = that.check_ids;

            //请求邀请者列表
            that.$http.post(that.adminApi.api_url + "/Radiostation/bindradio_relation_goods", formData, {
                emulateJSON: true
            }).then(
                function(res) {
                    // 处理成功的结果
                    that.$message({
                        type: 'success',
                        message: `操作提示: ${ '绑定成功' }`
                    });
                    that.$router.go(-1);
                },
                function() {
                    // 处理失败的结果
                    that.$message({
                        type: 'error',
                        message: `操作提示: ${ '处理异常' }`
                    });
                });
        }
    }
}
